<?php

namespace app\common\model;

use app\common\basic\BaseModel;

/**
 * 客户元数据模型
 */
class CrmCustomerMetas extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';
    protected $table = 'vk_crm_customer_metas';

    /**
     * 更新或创建元数据
     * @param array $where 查询条件
     * @param array $data 更新数据
     * @return static
     */
    public static function updateOrCreate(array $where, array $data = [])
    {
        $model = self::where($where)->find();
        if (!$model) {
            $model = new self();
            $model->setAttrs(array_merge($where, $data));
        } else {
            $model->setAttrs($data);
        }
        $model->save();
        return $model;
    }
}